package com.budwk.app.sqfwV2.generator.centuryCitySecurity.pdf;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.BasePdfParamDTO;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.BaseTemplatePdfGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.SqfwPdfCreateCommonBO;
import com.budwk.app.sqfwV2.dto.dto.SafeCheckTaskPdfDTO;
import com.budwk.app.util.StrUtil;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 本代码由代码生成器生成，版本号1.0
 */
public class CenturyCityNinePlacesGenerater extends BaseTemplatePdfGenerator{

    /**
    * 判断使用使用这个generator生成pdf
    *
    * @param pdfDTO 创建pdf数据素材
    * @return 结果
    */
    @Override
    public boolean pdfCreateConditionCheck(SqfwPdfCreateCommonBO pdfDTO) {
        return true;
    }

    @Override
    public String getTemplateName() {
        return "sqfwV2/centuryCitySecurity/centuryCityNineSmallPlaces.docx";
    }

    @Override
    public void customerPopularPdfParam(Map<String, Object> paramMap, SqfwPdfCreateCommonBO commonParam) {
        // 在这里对一些数据进行填充 进行复杂的业务代码逻辑
        BasePdfParamDTO basePdfParam = commonParam.getBasePdfParamDTO();
        paramMap.put("community", StrUtil.formatStr(basePdfParam.getCommunity()));
        paramMap.put("createUserName", StrUtil.formatStr(basePdfParam.getCreateUserName()));
        paramMap.put("downloadTime", LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN));
        // 13个问题
        SafeCheckTaskPdfDTO pdfDTO = JSONObject.parseObject(JSONObject.toJSONString(commonParam.getAbstractCustomerPdfCreateField()), SafeCheckTaskPdfDTO.class);
        paramMap.put("isHydrantBlocked", getKey(pdfDTO.getIsHydrantBlocked().getKey()));
        paramMap.put("isHydrantOperational", getKey(pdfDTO.getIsHydrantOperational().getKey()));
        paramMap.put("placeFireExtinguishersNumber", pdfDTO.getPlaceFireExtinguishersNumber());
        paramMap.put("isExtinguisherExpiredOrDamaged", getKey(pdfDTO.getIsExtinguisherExpiredOrDamaged().getKey()));
        paramMap.put("isAbleToUseFireExtinguisher", getKey(pdfDTO.getIsAbleToUseFireExtinguisher().getKey()));
        paramMap.put("isUnauthorizedElectricGasConnection", getKey(pdfDTO.getIsUnauthorizedElectricGasConnection().getKey()));
        paramMap.put("isExposedWiringGasLines", getKey(pdfDTO.getIsExposedWiringGasLines().getKey()));
        paramMap.put("isThereAnyBlockage", getKey(pdfDTO.getIsThereAnyBlockage().getKey()));
        paramMap.put("residentialFlag", getKey(pdfDTO.getResidentialFlag().getKey()));
        paramMap.put("whetherFlamExplosive", getKey(pdfDTO.getWhetherFlamExplosive().getKey()));
        paramMap.put("isGasAlarmInstalled", getKey(pdfDTO.getIsGasAlarmInstalled().getKey()));
        paramMap.put("isProperlyInstalledGasAlarm", getKey(pdfDTO.getIsProperlyInstalledGasAlarm().getKey()));
        paramMap.put("isNewFuelUsed", getKey(pdfDTO.getIsNewFuelUsed().getKey()));
        paramMap.put("isConstructingFloors", getKey(pdfDTO.getIsConstructingFloors().getKey()));
        paramMap.put("otherSituation", StrUtil.formatStr(pdfDTO.getOtherSituation()));
        paramMap.put("inspectionDate", LocalDateTimeUtil.format(pdfDTO.getInspectionDate(), DatePattern.NORM_DATE_PATTERN));

        // 巡查人员签名（以前的a19）
        paramMap.put("checkedUnitLeader", "");
        paramMap.put("problemData", StrUtil.formatStr(pdfDTO.getIsConstructingFloors().getProblemData()));
        if (StringUtils.isNotEmpty(pdfDTO.getCheckedUnitLeader())) {
            paramMap.put("checkedUnitLeader", CommonFormOfficeUtils.addWordPicture(pdfDTO.getCheckedUnitLeader(), 1.0F));
        }
    }

    private boolean getKey(String key) {
        return key.equals("true");
    }
}
